package com.dkcd.chenshiproject.tabHostActivity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.dkcd.chenshiproject.MainActivity;
import com.dkcd.chenshiproject.R;
import com.dkcd.chenshiproject.adapter.MusicAdapter;
import com.dkcd.chenshiproject.entity.Song;
import com.dkcd.chenshiproject.util.MusicUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MusicPavilionActivity extends Fragment {

    private LinearLayout linearLayout;
    private ListView listView;
    private AutoCompleteTextView musicPavilionSearch;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Log.e("TAG", "onCreate: 音乐馆Activity运行了");
/*        init();
        initView();*/
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        Log.e("TAG", "onCreateView: fragment_index_map执行了");
        // Inflate the layout for this fragment
        init(inflater);
        initView();
        return inflater.inflate(R.layout.activity_music_pavilion, container, false);
    }


    private void init(LayoutInflater inflater){
        LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.activity_music_pavilion, null);
        listView = (ListView) layout.findViewById(R.id.music_pavilion_list);
    }

    private void initView(){
        //初始化 音乐馆 listview
        List<Song> musicData = MusicUtils.getMusicData(getActivity().getApplicationContext());
        List<String> songsName = new ArrayList<>();
        for (Song musicDatum : musicData) {
            String song = musicDatum.song;
            Log.e("TAG", song );
            songsName.add(song);
        }
        System.out.println(musicData);
        MusicAdapter myAdapter = new MusicAdapter(getActivity(), musicData);
        System.out.println(songsName);
        String[] strings = (String[]) songsName.toArray();
        ArrayAdapter<String> stringArrayAdapter = new ArrayAdapter<>(getContext(),
                android.R.layout.simple_dropdown_item_1line,strings);
        musicPavilionSearch.setAdapter(stringArrayAdapter);
        listView.setAdapter(myAdapter);
    }


}